/**
@Test 导入 org.junit.Test 这个包
@Deprecated  禁用方法
防御禁止
1.固定数组
2.禁止null
3.返回错误的对象 提示
4.deprecated 禁用方法

GUAVA 可用于开发手机app
版本下载:https://repo1.maven.org/maven2/com/google/guava/guava/
google的 -》1.集合  2.缓冲 3.原生类型支持 4.并发库 5.通用注解 字符串处理，6.I/O等等
 
 1.不可变集合
 2.新集合类型
 3.强大的集合工具类
 4.扩展工具类
 
 guava组件
 1.只读设置
 2.函数式编程：过滤器
 3.函数式编程：转换
 4.组合式函数编程
 5.加入约束：非空,长度验证
 6.集合操作：交集，差集，并集
 7.Multiset:无序可重复
 8.Multimap key：可以重复
 9.BiMap：双向Map（bidirectional Map)键与值不能重复
 10.双键的Map->Table->rowKey+columnKye+value
 
 */
/*
package com.leo.guava;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;

import org.junit.Test;

import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.BiMap;
import com.google.common.collect.Collections2;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
import com.google.common.collect.Table;
import com.google.common.collect.Table.Cell;

import java.util.Set;

public class Outer_guava {
	@Test
	public void testguava() {
		System.out.println("------------guava----------");
		Arrays_aslist();
		Collections_unmodifiableList();
		guava_ImmutableList();
		s1();
		s2();
		guva_composeandtransform();
		intersection_difference_union();
		multiset();
		Multimap();
		bimap();
		table();
	}
	
	class Inner_Collection2{
		
		//2.过滤
		private void filter() {
			System.out.println("-------GOOLE_(final)Collections2工具类filter过滤器接口------");
			List<String> list=Lists.newArrayList("jack","tom","java","jay");
			//JAVA的collection接口  google的具体实现最终类Collection2的filter
			//google的Collection2 把功能全部封装进这个工具类中，转换行为在其内部类执行
			Collection<String> result=Collections2.filter(list,str->str.startsWith("j"));
			result.forEach(System.out::println);
		}
		
		//3.转换
		private void Transform() {
			System.out.println("-------Transform------");
			Set<Long> timeSet =Sets.newHashSet(20121212L,20170520L,20160808L);
			Collection<String> timeCollect=Collections2.transform
					(timeSet,(e)->new SimpleDateFormat("yyyy-mm-dd").format(e));
			timeCollect.forEach(System.out::println);
		}
	}	
	//2.过滤的封装 test
	public void s1( ) {
		Outer_guava og=new Outer_guava();
		Outer_guava.Inner_Collection2 ic=og.new Inner_Collection2();
		ic.filter();
	}
		
	//3.转换的封装 test
	public void s2( ) {
		Outer_guava og=new Outer_guava();
		Outer_guava.Inner_Collection2 ic=og.new Inner_Collection2();
		ic.Transform();	
	}
	
	//只读设置
	private void Arrays_aslist() {
		System.out.println("------------Arrays_aslist----------");
		List<String> list_readonly=Arrays.asList("tom","lucy","tim","hom");
		//因为asList 是一个固定的arraylist 。如出现null的情况就会返回一个错误的对象。无法添加和删除，可以替换。
		//list_readonly.add("newbe");
		list_readonly.set(3, "dd");
		list_readonly.forEach(System.out::println);
	}
	
	//只读设置
	private void Collections_unmodifiableList() {
		System.out.println("------------Collections_unmodifiableList----------");
		List<String> list_readonly=Arrays.asList("tom","lucy","tim","hom");
		//方法都被返回一个错误的对象 
		List <String> readList=Collections.unmodifiableList(list_readonly);
		//方法都被返回一个错误的对象 add,remove ,set...
		//readList.set(3, "tt");
		readList.forEach(System.out::println);	
	}
	
	//只读设置
	private void guava_ImmutableList() {
		System.out.println("------------guava_ImmutableList----------");
		ImmutableList<String> iList=ImmutableList.of("tom","sos");
		//remove方法被deprecated 禁用了
		//iList.remove("s");	
	}
	
	//3.组合
	private void guva_composeandtransform() {
		System.out.println("------------guva_composeandtransform----------");
		List<String > list=Lists.newArrayList("tom", "jack","jim","lucy","marry");
		Function<String,String> f1=new Function<String,String>(){
			public String apply(String t) {
				return t.length()>4?t.substring(0,4):t;
			}	
		};
		Function<String,String> f2=new Function<String,String>(){
			public String apply(String t) {
				return t.toUpperCase();
			}		
		};
		
		Function<String,String>f =Functions.compose(f1,f2);
		Collection<String> result=Collections2.transform(list, f);
		result.forEach(System.out::println);
	}
	
	//6.集合操作：交集（相同部分），差集（2个set相交，另一个不相交部分），并集(去除重复，2个不同部分）
	private void intersection_difference_union() {
		System.out.println("------------集合操作：交集（相同部分），差集（s1s2相比，s1不同的部分），并集(2个不同部分+1次相同）---------");
		Set<Integer> set1=Sets.newHashSet(1,2,3,4);
		Set<Integer> set2=Sets.newHashSet(2,3,4,5);
		SetView<Integer> v1=Sets.intersection(set1, set2);
		v1.forEach(System.out::println);
		System.out.println("\n");
		SetView<Integer> v2=Sets.difference(set1, set2);
		v2.forEach(System.out::println);
		System.out.println("\n");
		SetView<Integer> v3=Sets.union(set1, set2);
		v3.forEach(System.out::println);
		System.out.println("\n");
	}
	
	//7.Multiset:无序可重复 
	public void multiset() {
		System.out.println("-----multiset-----");
		String s="tom jim lucy gogo gogo";
		String [] ss=s.split(" ");
		HashMultiset<String> set=HashMultiset.create();
		for(String str:ss) {
			set.add(str);
		}
		
		//Set去重  Mutiset.elementSet 转换类型
		Set<String> set2 =set.elementSet();
		for(String str:set2) {
			System.out.println(str+":"+set.count(str));
		}
	}
	
	//8.Multimap key：可以重复
	public void Multimap() {
		Map<String,String> map=new HashMap<>();
		map.put("书名1","tom");
		map.put("书名2","lucy");
		map.put("书名3", "jim");
		map.put("书名4", "gogo");
		
		com.google.common.collect.Multimap<String,String> mmap=ArrayListMultimap.create();
		Iterator<Map.Entry<String,String>> iter=map.entrySet().iterator();
		while(iter.hasNext()) {
			Map.Entry<String, String> entry=iter.next();
			mmap.put(entry.getValue(),entry.getKey());
		}
		
		Set<String> KeySet=mmap.keySet();
		for(String key:KeySet) {
			Collection<String> values=mmap.get(key);
			System.out.println(key+"->"+values);
		}
	}
	
	//9.BiMap:双向 Map（bidirectional ）键与值不能重复
	public void bimap() {
		System.out.println("-----bimap-----");
		BiMap<String,String> map=HashBiMap.create();
		map.put("finally_test", "18201583398");
		map.put("bin_test", "18388881521");
		String name=map.inverse().get("18201583398");
		System.out.println("反转看key:"+name);
	}
	//10.
	public void table() {
		System.out.println("-----table-----");
		Table<String,String,Integer> table=HashBasedTable.create();
		table.put("tom", "java", 100);
		table.put("jick","php",20);
		table.put("momo","c" , 2);
		Set<Cell<String,String,Integer>>cells=table.cellSet();
		for(Cell c:cells) {
			System.out.println(c.getRowKey()+"-"+c.getColumnKey()+"-"+c.getValue());
		}
		
	}
}
*/

